package com.wicket.okrframework.base.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wicket.okrframework.base.service.MHypertextContentService;
import com.wicket.okrframework.base.service.dto.req.QueryHypertextContentDetailReq;
import com.wicket.okrframework.common.exception.BizException;
import com.wicket.okrframework.common.util.CommonFunctionHelper;
import com.wicket.okrframework.dal.mapper.mbg.HypertextContentMapper;
import com.wicket.okrframework.dal.po.mbg.HostType;
import com.wicket.okrframework.dal.po.mbg.HypertextContent;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.ArrayList;

/**
 * @author ：
 * @since 2022/1/19 15:39
 *
 *
 * @version 1.0
 */
@Service
public class MHypertextContentServiceImpl
        extends ServiceImpl<HypertextContentMapper, HypertextContent>
        implements MHypertextContentService {

    @Autowired
    HypertextContentMapper hypertextContentMapper;

    /**
   * 1-2-15查询超文本内容详情[3133]
   * gen by moon at 10/16/2022, 1:02:18 AM
   */
 @Trace(operationName = "1-2-15查询超文本内容详情")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  HypertextContent  queryHypertextContentDetail(QueryHypertextContentDetailReq reqDto) {
     
        try {
         reqDto.setIsValid("FALSE");
            QueryWrapper<HypertextContent> queryWrapper = new QueryWrapper<>();
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, new ArrayList<>());
            queryWrapper.orderByDesc("create_time");
            List<HypertextContent> retList = super.list(queryWrapper);
            if(retList!=null && retList.size()>0){
                HypertextContent retData = retList.get(0);

                return retData;
            }
            return null;
      } catch (Exception e) {
          e.printStackTrace();
          throw new BizException("-1",e,false);
      }
  }
/**
   * 1-2-15新增底层框架超文本内容[6646]
   * gen by moon at 5/13/2023, 9:07:10 PM
   */
 @Trace(operationName = "1-2-15新增底层框架超文本内容")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  String  addFrameworkHypertextContent(HypertextContent hypertextContent) {
     hypertextContent.setHypertextContentId(CommonFunctionHelper.getUid());//DISTRIBUTED_ID
hypertextContent.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
hypertextContent.setCreateInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
hypertextContent.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
hypertextContent.setCreateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
hypertextContent.setIsValid("FALSE");
hypertextContent.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
hypertextContent.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
     if(super.save(hypertextContent)){
        return hypertextContent.getHypertextContentId();
     }else {
        return "-1";
     }

  }

}

